﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;


public partial class product_card_user_RewardConvertion : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {


        String custId = Session["custID"] as String;
        Object Total = Session["limitLeft"];
        if (Total != null)
        {

            if (!Util.IsBlank((String)Total))
            {
                this.TextBox4.Text = "Quantity:";
                this.TextBox4.Visible = true;
                this.TextBox4.Text = (String)Total;
                this.TextBox4.Visible = false;

            }
            else
            {
                this.TextBox4.Visible = false;

            }

        }
         Object Amount = Session["amountSpent"];
        if (Amount != null)
        {

            if (!Util.IsBlank((String)Amount))
            {
                this.TextBox7.Text = "amountSpent:";
                this.TextBox7.Visible = true;
                this.TextBox7.Text = (String)Amount;
                this.TextBox7.Visible = true;

            }
            else
            {
                this.TextBox7.Visible = false;

            }

 


        }



        Object TextBox6 = Session["userId"];
        if (TextBox6 != null)
        {

            if (!Util.IsBlank((String)TextBox6))
            {
                this.TextBox6.Text = "userId:";
                this.TextBox6.Visible = true;
                this.TextBox6.Text = (String)TextBox6;
                this.TextBox6.Visible = false;

            }
            else
            {
                this.TextBox6.Visible = false;

            }

        }
        Button1.Text = "Add details";

        con.Open();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        double cashPoints = Convert.ToDouble(TextBox1.Text);
        double cash = Convert.ToDouble(TextBox7.Text);
        double limit = Convert.ToDouble(TextBox4.Text);

        double reducedLimit = limit - cash;
        TextBox5.Text = Convert.ToString(reducedLimit);






        if (TextBox3.Text == "")
        {
            TextBox3.Text = TextBox1.Text;

            Label1.Text = "" + DateTime.Now.ToLongTimeString();
            Label10.Text = "1";
            Button1.Enabled = false;

        }

    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Label1.Text = "";

        Label9.Text = "";
        Label10.Text = "";
        TextBox1.Text = "";
        TextBox7.Text = "";
        TextBox3.Text = "";
        Button1.Enabled = true;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        con.Open();
        String custId = Session["userId"] as String;
       

       
        

        SqlCommand se = new SqlCommand("SELECT reward FROM CALCULATEREWARD WHERE custID = '" + custId + "'");
        SqlCommand cmd = new SqlCommand("insert into CALCULATEREWARD values ('" + custId + "','" + Label1.Text + "','" + TextBox3.Text + "','" + Label12.Text + "','" + TextBox7.Text + "')", con);

        cmd.ExecuteNonQuery();




        Label9.Visible = true;
        Label9.Text = "Your data stored successfully!";
        GridView1.DataBind();

        con.Close();

    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (TextBox7.Text != null)
        {
            double cashPoints = Convert.ToDouble(this.TextBox7.Text);
            double rewardPoints = (cashPoints / 10);
            TextBox1.Text = Convert.ToString(rewardPoints);

        }
        else
        {
            double rewardPoints = Convert.ToDouble(this.TextBox1.Text);
            double cashPoints = (rewardPoints * 10);
            TextBox7.Text = Convert.ToString(cashPoints);
        }




    }
    protected void Reward_Click(object sender, EventArgs e)
    {
        Response.Redirect("Reward.aspx");
    }

    public string custId { get; set; }

    public object reducedLimit { get; set; }



public  string Amount { get; set; }}